﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Routing;
using System.Text;

public partial class MasterPage_Manager : System.Web.UI.MasterPage
{
    public string backgroundLogin = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        backgroundLogin = ResolveUrl("~/images/Advertis/green-apple-wallpaper.jpg");
        HttpCookie _user = Request.Cookies["userinfo"];
        StringBuilder sb = new StringBuilder();
        try
        {
            if (Request.Cookies["userinfo"] != null)
            {
                if (_user["username"] != null)
                {
                    signin_form.Visible = false;
                    using (Up1VNDataContext dc = new Up1VNDataContext())
                    {
                        var userinfo = dc.Users.Single(o => o.Users_Name == _user["username"]);
                        sb.Append("<img style='width:50px; height:50px' src='" + ResolveUrl("~/User/avatar/" + userinfo.Users_Avatar) + "' alt='' />");
                    }
                    sb.Append("Xin chào! <span><a href='" + ResolveUrl("~/" + _user["username"]) + "'>" + _user["username"] + "</a></span>");
                    sb.Append("&nbsp;&nbsp;<a href='" + ResolveUrl("~/Thoat.html") + "'>Thoát</a>");
                    signin_form.Visible = false;
                    ltrSetActive.Text = "<script>$(document).ready(function(){SetActiveTopLink(2);SetActivemenubar(6);});</script>";
                }
                else
                {
                    sb.Append("Xin chào! Khách");
                    loadUC();
                }
            }
            else
            {
                sb.Append("Xin chào! Khách");
                loadUC();
            }
        }
        catch (Exception ex)
        {
        }
        ltruserinformation.Text = sb.ToString();
    }
    private void loadUC()
    {
        PanelEditInfo.Visible = false;
        Control Ctrl = new Control();
        Ctrl = Page.LoadControl(ResolveUrl("~/UserControl/PointChange.ascx"));
        PanelViewuser.Controls.Add(Ctrl);
        Ctrl = Page.LoadControl(ResolveUrl("~/UserControl/DecodeWinning.ascx"));
        PanelViewuser.Controls.Add(Ctrl);
        Ctrl = Page.LoadControl(ResolveUrl("~/UserControl/Videos.ascx"));
        PanelViewuser.Controls.Add(Ctrl);
        Ctrl = Page.LoadControl(ResolveUrl("~/UserControl/SupportOnline.ascx"));
        PanelViewuser.Controls.Add(Ctrl);
    }
}
